﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Collections;
using System.Text;
using Proxy;
using System.Web.Services;
using SIM.Util;

namespace SIM.Geo.UI.Geo
{
    public partial class frmBuscarSondaje : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Listar();
            }

        }

        protected override void Listar()
        {
            try
            {
                using (SESondajeClient proxy = new SESondajeClient("BasicHttpBinding_ISESondaje"))
                {
                    var lista = proxy.ConsultarSondajes(this.txtNombreDDH.Text.Trim(), string.Empty, 0, 0, 0, enmClaseSondaje.DDH.GetHashCode());
                    this.rgLista.DataSource = lista;
                    
                    this.rgLista.DataBind();
                }

            }
            catch (Exception ex)
            {

                Logger.Error("frmActualizarUbiSondaje:Listar", ex);
            }
        }

        protected void rgLista_PageIndexChanged(object sender, GridPageChangedEventArgs e)
        {
            Listar();
        }

        protected void rgLista_SortCommand(object sender, GridSortCommandEventArgs e)
        {
            Listar();
        }

        protected void rgLista_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
        {
            this.Listar();
        }

        protected void rgLista_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName.CompareTo("Seleccionar") == 0)
            {
                //var item = (GridEditableItem)e.Item;
                //this.hidSeleccionado.Value = item.GetDataKeyValue("CodigoSondaje").ToString();
                ////Carga detalle de sondaje                
            }

            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Listar();
            }
        }

        protected void ibtnBuscar_Click(object sender, ImageClickEventArgs e)
        {
            this.Listar();
        }

        protected void rgLista_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                ImageButton btnSelect = (ImageButton)item["btnSelect"].Controls[0];
                string codigo = item.GetDataKeyValue("CodigoSondaje").ToString();
                btnSelect.Attributes.Add("onclick", "return RetonarValor('" + codigo + "');");

                //ImageButton ibtnSelect = (ImageButton)item.FindControl("ibtnSelect");
                //ibtnSelect.Attributes.Add("onclick", "return RetonarValor('" + ibtnSelect.CommandArgument + "')");
            }

        }
    }
}